<?php

class Mod_attendance extends Model {

    function Mod_attendance() {
        parent::model();
    }
//===============================this is  function for loading master page===============//
    function index() {
        $this->load->view('master');
    }

//===========================this is function for adding new attendance=================//
    
    function add() {
        $data_att = array(
            'car_type_name' => $this->input->post('card'),
            'att_date' => $this->input->post('txtdate'),
            'att_time' => $this->input->post('txtdrop'),
            'stu_id' => $this->input->post('student_name'),
            'stu_type' => $this->input->post('student'),
            'cla_id' => $this->input->post('class_name'),
            'teacher_id' => $this->input->post('teacher_name'),
            'att_status'=>1,
        );
        return $this->db->insert('tbl_attendence', $data_att);
    }

//===================this is function for select to view in attendance==================//
    
  function select_view() {
        $this->db->select('*');
        $this->db->from('tbl_attendence');
        $this->db->join('tbl_teacher', 'tbl_teacher.tea_id =  tbl_attendence.teacher_id');
        $this->db->join('tbl_class', 'tbl_attendence.cla_id=tbl_class.cla_id');
        $this->db->join('tbl_student', 'tbl_student.stu_id=tbl_attendence.stu_id');
        $this->db->join('tbl_stu_type', ' tbl_stu_type.stu_type_id = tbl_student.stu_type_id');
        $query_att = $this->db->get('');
        return $query_att;
        // else return false;
    }

    //-----------------this is function for using pagination ------------------
    
    /*function get_page_limit($start_row, $per_page) {
        $this->db->select('*');
        $this->db->from('tbl_attendence');
        $this->db->join('tbl_teacher', 'tbl_teacher.tea_id =  tbl_attendence.tea_id');
        $this->db->join('tbl_class', 'tbl_attendence.cla_id=tbl_class.cla_id');
        $this->db->join('tbl_student', 'tbl_student.stu_id=tbl_attendence.stu_id');
        $this->db->join('tbl_stu_type', ' tbl_stu_type.stu_type_id = tbl_student.stu_type_id');
     //   $this->db->limit( $start_row, $per_page);
       return $this->db->get('',$start_row, $per_page);
       
    }*/

    //===============this is function using for edit page attendance===============//
    
    function edit() {
        $data = array(
            'stu_id' => $this->input->post('student_name'),
            'teacher_id' => $this->input->post('teacher_name'),
            'cla_id' => $this->input->post('class_name'),
            'att_date' => $this->input->post('txtdate'),
            'att_time' => $this->input->post('txtdrop'),
            'stu_type' => $this->input->post('student'),
            'car_type_name' => $this->input->post('card')
        );
        $this->db->where('att_id', $this->uri->segment(3));
        if ($this->db->update('tbl_attendence', $data))
            return true;
        else
            return false;
    }

    //========================this is function for using select edit in attendance==============//
    
    function select_edit() {

        $foredit = $this->db->where('att_id', $this->uri->segment('3'));
        return $this->db->get('tbl_attendence');
    }

//======================this is function for using delect attendance=================//
    
    function delete() {
        $id = $this->uri->segment('3');
        $this->db->delete('tbl_attendence', array('att_id' => $id));
    }
    
    //--------testing------------------------------------------------------------
    
 /* function getAttendance($num, $uri3){
			
			//if user search
			$this->input->post("txt_stuName")==true?$this->db->like('stu_name',$this->input->post("txt_stuName")):"";
			$this->input->post("txt_ngoName")==true?$this->db->like('car_type_name',$this->input->post("txt_ngoName")):"";
			$this->input->post("txt_claName")==true?$this->db->like('cla_name',$this->input->post("txt_claName")):"";
                                                
			//$this->db->where('stu_id > ',0);
			$this->db->where('stu_status',1);
			$this->db->where('cla_status',1);
			$this->db->where("tea_status",1);
                                                $this->db->where('att_status',1);
                                                
                                                
         $this->db->select('*');
         $this->db->from('tbl_attendence');               
        $this->db->join('tbl_teacher', 'tbl_teacher.tea_id =  tbl_attendence.teacher_id');
        $this->db->join('tbl_class', 'tbl_attendence.cla_id=tbl_class.cla_id');
        $this->db->join('tbl_student', 'tbl_student.stu_id=tbl_attendence.stu_id');
        $this->db->join('tbl_stu_type', 'tbl_stu_type.stu_type_id = tbl_student.stu_type_id');
        
			
			$this->db->limit($num, $uri3);
			return $this->db->get();
		}
                
                //--this is 
                
                function getNum(){
			
			
			//if user search
			$this->input->post("txt_stuName")==true?$this->db->like('stu_name',$this->input->post("txt_stuName")):"";
			$this->input->post("txt_ngoName")==true?$this->db->like('car_type_name',$this->input->post("txt_ngoName")):"";
			$this->input->post("txt_claName")==true?$this->db->like('cla_name',$this->input->post("txt_claName")):"";
			//$this->db->where('stu_id > ',0);
                                                
			$this->db->where('stu_status',1);
			$this->db->where('cla_status',1);
			$this->db->where("tea_status",1);
                                                 $this->db->where('att_status',1);
                                                
          $this->db->select('*');
            $this->db->from('tbl_attendence');                                       
        $this->db->join('tbl_teacher', 'tbl_teacher.tea_id =  tbl_attendence.teacher_id');
        $this->db->join('tbl_class', 'tbl_attendence.cla_id=tbl_class.cla_id');
        $this->db->join('tbl_student', 'tbl_student.stu_id=tbl_attendence.stu_id');
        $this->db->join('tbl_stu_type', 'tbl_stu_type.stu_type_id = tbl_student.stu_type_id');
        return $this->db->get()->num_rows();
		}*/
    
//======================this is function for searching attendance=======================// 
		
function get_attendance($p=null) { // $p is array
         
        if ($this->input->post($this->dbf->stu_name) && $this->input->post($this->dbf->stu_name) != '')
        $this->db->like($this->dbf->stu_name, $this->input->post($this->dbf->stu_name));
        $this->db->select('*');
        $this->db->from('tbl_attendence');
        $this->db->limit($p[0], $p[1]);
        $this->db->where('att_status',1);
        $this->db->order_by('att_id','desc');
         $this->db->join('tbl_teacher', 'tbl_teacher.tea_id =  tbl_attendence.teacher_id');
        $this->db->join('tbl_class', 'tbl_attendence.cla_id=tbl_class.cla_id');
        $this->db->join('tbl_student', 'tbl_student.stu_id=tbl_attendence.stu_id');
        $this->db->join('tbl_stu_type', 'tbl_stu_type.stu_type_id = tbl_student.stu_type_id');
        return $this->db->get();
    }
}